//
//  IfengCommentSingleFloorLabel.m
//  IfengNews
//
//  Created by 王 芬 on 13-10-16.
//
//

#import "IfengCommentSingleFloorLabel.h"
#import "IfengLabel.h"
@implementation IfengCommentSingleFloorLabel
@synthesize index = _index;
@synthesize superCell = _superCell;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
      self.userInteractionEnabled = YES;
    }
    return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self setLabelHightedBgColor];
  UITouch *touch = [touches anyObject];
  touchTimeInterval = [touch timestamp];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
  //do something
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
//  [self performSelector:@selector(setLableBgWithIsAddSelectedColor:) withObject:@"NO" afterDelay:0.2];
    [self setLabelCommonBgColor];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
//  [self performSelector:@selector(setLableBgWithIsAddSelectedColor:) withObject:@"NO" afterDelay:0.2];
    [self setLabelCommonBgColor];
  UITouch *touch = [touches anyObject];
  CGPoint locate = [touch locationInView:self];
  CGPoint locateInWindow = [self.window convertPoint:locate fromView:self];
  UIView *ifengLabel = [self.superCell viewWithTag:10];
  if (!ifengLabel || ![ifengLabel isMemberOfClass:[IfengLabel class]]) {
    return;
  }
  touchTimeInterval = [touch timestamp] - touchTimeInterval;
  NSInteger tapCount = touch.tapCount;
  if(tapCount == 1 && touchTimeInterval <= 1.0){
    if(((IfengLabel *)ifengLabel).delegate && [((IfengLabel *)ifengLabel).delegate respondsToSelector:@selector(ifengLabelDidSingleClickAtIndex:withData:withLevel:withLocateInWindow:withLocateInCell:withSizeOfCell:withView:)]){
      [((IfengLabel *)ifengLabel).delegate ifengLabelDidSingleClickAtIndex:[NSNumber numberWithInt:self.index]
                                                                  withData:((IfengLabel *)ifengLabel).dataDic
                                                                 withLevel:[NSNumber numberWithInt:((IfengLabel *)ifengLabel).level]
                                                        withLocateInWindow:locateInWindow withLocateInCell:locate withSizeOfCell:self.frame.size withView:self];

    }
  }
}

- (void)setLabelHightedBgColor
{
    UIColor *bgColor = RGB(0xcd, 0xcd, 0xcd);
    self.backgroundColor = bgColor;
}

- (void)setLabelCommonBgColor
{
    UIColor *bgColor = RGB(0xed, 0xf0, 0xf2);
    self.backgroundColor = bgColor;
}
@end
